package com.fmjava.service_base.exception;

import com.fmjava.utils.ResponseResult;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/*
 *@ClassName GlobalExceptionHamdler
 *@Description TODO
 *@Author 吃麻椒的花酱
 *@Date 2021/7/2 20:29
 *@Version 1.0
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    //全局异常处理器, 只要发生了异常,如果在自己控制当中 没有去捕获 , 就会到此控制器
    @ResponseBody
    @ExceptionHandler(Exception.class)
    public ResponseResult error(Exception e) {
        e.printStackTrace();
        return ResponseResult.error();
    }

    @ResponseBody
    @ExceptionHandler(MyException.class)
    public ResponseResult error(MyException e) {
        return ResponseResult.error().code(e.getCode()).message(e.getMessage());
    }
}
